package com.test.daily.leetcode.y2022.m07.day0724.v01;

/**
 * @author Tom on 2022/7/24
 */
public class Solution {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int N = distance.length;
        int[] sum = new int[N+1];
        sum[0] = 0;
        for (int i = 1; i <= N; i++) {
            sum[i] =sum[i-1] + distance[i-1];
        }
        if(start > destination){
            int tmp = destination;
            destination = start;
            start = tmp;
        }
        int d1 = sum[destination] - sum[start];
        int d2 = sum[N] - d1;
        return Math.min(d1, d2);
    }
}
